import {ItemInterface} from "./itemInterface";
import {CreateDomWithList} from "./CreateDomWithList";
import {ConfigureElementForVNode} from "./ConfigureElementForVNode";
import {init} from "snabbdom/src/package/init";
import {styleModule} from "snabbdom/src/package/modules/style";
import {eventListenersModule} from "snabbdom/src/package/modules/eventlisteners";

let patch = init([
    styleModule, eventListenersModule
]);

let RemoveSingleItem = (rank:number, originalData:Array<ItemInterface>) => {
    let oldDOM = CreateDomWithList(originalData);
    ConfigureElementForVNode(oldDOM);

    let dataToCopy = originalData.filter(e => e.rank !== rank);
    originalData.splice(0);
    dataToCopy.forEach(e => {
        originalData.push(e);
    });

    let newDOM = CreateDomWithList(originalData);
    ConfigureElementForVNode(newDOM);
    patch(oldDOM, newDOM);

};

export {RemoveSingleItem};